<template>
    <h2>修改房价信息</h2>
    <table>
    <tr>
        <td>房价名称</td>
        <td>
            <input type="text" v-model="poisk.pname">
        </td>
    </tr>
    <tr>
        <td>房价</td>
        <td>
            <input type="text" v-model="poisk.price">
        </td>
    </tr>
    <tr>
        <td>房间类型</td>
        <td>
            <select v-model="poisk.typeid">
                <option value="">请选择</option>
                <option :value="is.id" v-for="is in type">{{ is.rname }}</option>
            </select>
        </td>
    </tr>
    <tr>
        <td></td>
        <td>
            <input type="button" value="修改" @click="upwoomws">
        </td>
    </tr>
   </table>
  </template>
  
  <script setup lang="ts">
  import {onMounted, reactive, toRefs} from 'vue'
  import {useRouter,useRoute} from 'vue-router'
  import axios from 'axios'
  const router=useRouter()
  const route=useRoute()

  let data:any=reactive({
    type:[],
    poisk:[]
  })
  let {type,poisk} =toRefs(data)

  onMounted(()=>{
    gettype()
    getfill()
  })

  const gettype=()=>{
    axios({
        url:'/api/Price/Bindtype',
        method:'get'
    })
    .then(res=>{
        type.value=res.data.data;
    })
  }

  const getfill=()=>{
    let obj={
        pid:route.query.pid
    }
    axios({
        url:'/api/Price/Selid',
        method:'get',
        params:obj
    })
    .then(res=>{
        poisk.value=res.data.data;
    })
  }

  const upwoomws=()=>{
    let obj={
        "pid": route.query.pid,
        "typeid": poisk.value.typeid,
  "pname": poisk.value.pname,
  "price": poisk.value.price,
  "pstates": 1,
  "isdel": false
    }
    axios({
        url:'/api/Price/Updprice',
        method:'post',
        data:obj
    })
    .then(res=>{
        if(res.data.data==1){
            alert("修改房价信息成功")
            router.push('showprice')
        }else{
            alert("修改房价信息失败")
        }
    })
  }
  </script>
  
  <style scoped>
  
  </style>